package com.dengqi.mymodule.activity.network.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.dengqi.mymodule.R;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @Author: dengqi
 * @CreateDate: 2020/10/19 17:31
 * @Description: 各种卡
 */
public class CardAdapter<T> extends BaseAdapter<T, CardAdapter.ViewHolder> {


    @Override
    public CardAdapter.ViewHolder onSubCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_card, parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onSubBindViewHolder(T object, CardAdapter.ViewHolder holder, int position) {
        if(object instanceof ViewData){
//            holder.iv_pic
            holder.tv_title.setText(((ViewData) object).getAdapterTitle());
            holder.tv_price.setText("¥"+((ViewData) object).getAdapterPrice());
            holder.tv_time.setText(((ViewData) object).getAdapterTime()+"分钟/次");
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_pic;
        TextView tv_title, tv_price, tv_time;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_pic = itemView.findViewById(R.id.iv_pic);
            tv_title = itemView.findViewById(R.id.tv_title);
            tv_price = itemView.findViewById(R.id.tv_price);
            tv_time = itemView.findViewById(R.id.tv_time);
        }
    }

    public interface ViewData {
        String getAdapterImgUrl();
        String getAdapterTitle();
        String getAdapterPrice();
        String getAdapterTime();
    }

}
